1. Field of the Invention
The present invention relates to image processing devices and methods, and programs therefor and, more specifically, to image processing devices and methods by which color data is determined in accordance with distances from a specific point to graphically represent polygons, and programs for executing such methods.
2. Description of the Background Art
The conventional process of shading polygon surfaces in accordance with a light source is generally carried out as follows.
FIGS. 7A and 7B are diagrams for illustrating such a conventional shading process. Here, in this description, coordinate values are represented by ( ), while color data by [ ].
In the conventional process, distances from a light source to each vertex of a polygon to be processed are first calculated. In the example of FIG. 7A, coordinate values (x, y, z) of the light source are (0, 10, 0), those for a vertex A of the polygon are (10, 10, 0), those for a vertex B are (30, 20, 0), and those for a vertex C are (30, 0, 0). Therefore, the distance from the light source to the vertex A is xe2x80x9c10xe2x80x9d, and the distance from the light source to the vertex B or to the vertex C is xe2x80x9c31.6xe2x80x9d. Here, a distance-between-two-point D between coordinate values (I, J, K) and coordinate values (i, j, k) can be, as is well known, calculated by the following equation:
D={square root over ( )}{(Ixe2x88x92i)2+(Jxe2x88x92j)2+(Kxe2x88x92k)2}
Next, depending on thus calculated distance-between-two-point D, color data [r, g, b] is determined for each of the vertexes of the polygon. In this example, presumably, color data determined for the vertex A is [255, 255, 255] being white, and color data determined for both the vertex B and the vertex C is [0, 0, 0] being black.
Lastly, a shading process is carried out based on the color data determined for each of the vertexes of the polygon, and in the polygon, every pixel is complemented by color. FIG. 7B shows the polygon to which the shading process is applied under the conditions shown in FIG. 7A. As shown in FIG. 7B, in the conventional shading process, the color data of each pixel in the polygon shows a gradual color change in accordance with the difference in color data among the vertexes. For example, the color data of coordinate values (20, 5, 0) in the polygon is [r, g, b]=[128, 128, 128].
In the above conventional process, however, the distance to the light source is used as the basis for determining color data for each vertex of the polygon. Accordingly, as shown in FIG. 7A, there would be no problem if the light source is provided outside of the polygon to be processed. If the light source is provided inside of the polygon, however, the following problem arises.
As shown in FIG. 8A, in the case where the light source positions inside of the polygon, specifically when the distance therefrom is equal to all of the vertexes, determining color data for each of the vertexes of the polygon in accordance with the distance to the light source results all in the same data. If this is the case, if the shading process is applied by using the resultant color data of a kind, as shown in FIG. 8B, the polygon will be color-filled in its entirety by the same color data as the vertexes. Therefore, the processing result will be a far cry from the actual shading as shown in FIG. 9 which is expected to be.
For the purpose of overcoming such a problem, the polygon may be divided into smaller pieces, and the above shading process may be applied to each of the divided polygon pieces. Such image processing, however, definitely places a heavy load on devices, and thus large-sized high-performance computers may be a possibility, for example, but home personal computers and game machines have a practical difficulty.
Therefore, an object of the present invention is to provide image processing devices and methods by which a polygon analogous to its actual image can be produced through a shading process without placing a heavy load on devices even if there is a light source inside of the polygon, and programs therefor.
The present invention has the following features to attain the object above.
A first aspect of the present invention is directed to an image processing device including a gradation part for generating color data on a pixel basis of a polygon for gradation representation between vertexes of the polygon based on what color each of the vertexes has, and the device comprises coordinate value input means, a coordinate value read part, a distance calculation part, and a color determination part.
The coordinate value input part inputs, to the gradation part, coordinate values of each of the vertexes of the polygon as color data. The coordinate value read part reads, as coordinate values of each of the pixels, color data of each pixel of the polygon generated by the gradation part based on the data provided by the coordinate value input part. The distance calculation part calculates a distance between the coordinate values of each of the pixels of the polygon read by the coordinate value read part, and coordinate values of a specific point. The color data determination part determines the color data of each of the pixels of the polygon in accordance with the distance calculated by the distance calculation part.
As described above, in the first aspect, a shading process is applied to coordinate values of each vertex of a polygon, and by using coordinate values of each pixel thus obtained thereby, the color of the light source and the texture color, for example, are changed in accordance with the distance from a specific point to each of the pixels. In this manner, a polygon analogous to its actual image can be produced through the shading process without placing a heavy load on devices even if there is a light source inside of the polygon.
Preferably, the coordinate value input part inputs, to the gradation part, a value obtained by dividing the coordinate values of each of the vertexes of the polygon by a predetermined value to have the value fall in a range of color data processable by the gradation part, and the distance calculation part regards the value obtained by dividing the coordinate values of the specific point by the predetermined value as the coordinate values of the specific point for distance calculation.
As such, by dividing the coordinate values of each of the vertexes of the polygon by a predetermined value to round those into any appropriate coordinate values, the coordinate values of each vertex of the polygon can be handled as the color data.
Here, when the specific point is a position of a light source, the color data determination part may determine, by referring to a brightness of the light source, a brightness of each of the pixels of the polygon according to the distance calculated by the distance calculation part.
As such, by changing the brightness of each pixel of the polygon in accordance with the distance from the light source, such representation as the light is falling thereon can be realized.
Further, when the specific point is a position of a camera, the color data determination part may determine, with reference to the position of the camera, a color of each of the pixels of the polygon through blurring according to the distance calculated by the distance calculation part.
As such, by changing the color of each pixel of the polygon in accordance with the distance from the camera, depth field representation can be realized from the camera""s viewpoint.
A second aspect of the present invention is directed to an image processing method using a gradation part for generating color data on a pixel basis of a polygon for gradation representation between vertexes of the polygon based on what color each of the vertexes has, and the method includes an inputting step, a reading step, a calculating step, and a determining step.
In the inputting step, coordinate values of each of the vertexes of the polygon is inputted to the gradation part as color data. In the reading step, as coordinate values of each of the pixels, color data of each pixel of the polygon generated by the gradation part is read based on the inputted data. In the calculating step, calculated is a distance between the coordinate values of each of the pixels of the read polygon, and coordinate values of a specific point. In the determining step, the color data of each of the pixels of the polygon is determined in accordance with the calculated distance.
As described above, in the second aspect, a shading process is applied to coordinate values of each vertex of a polygon, and by using coordinate values of each pixel thus obtained thereby, the color of the light source and the texture color, for example, are changed in accordance with the distance from a specific point to each of the pixels. In this manner, a polygon analogous to its actual image can be produced through the shading process without placing a heavy load on devices even if there is a light source inside of the polygon.
Preferably, an inputting step is further included to input, to the gradation part, a value obtained by dividing the coordinate values of each of the vertexes of the polygon by a predetermined value to have the value fall in a range of color data processable by the gradation part. In the calculating step, the value obtained by dividing the coordinate values of the specific point by the predetermined value is regarded as the coordinate values of the specific point for distance calculation.
As such, by dividing the coordinate values of each of the vertexes of the polygon by a predetermined value to round those into any appropriate coordinate values, the coordinate values of each vertex of the polygon can be handled as the color data.
Here, when the specific point is a position of a light source, the determining step may determine, by referring to a brightness of the light source, a brightness of each of the pixels of the polygon according to the calculated distance.
As such, by changing the brightness of each pixel of the polygon in accordance with the distance from the light source, such representation as the light is falling thereon can be realized.
Further, when the specific point is a position of a camera, the determining step may determine, with reference to the position of the camera, a color of each of the pixels of the polygon through blurring according to the calculated distance.
As such, by changing the color of each pixel of the polygon in accordance with the distance from the camera, depth field representation can be realized from the camera""s viewpoint.
A third aspect of the present invention is directed to a program for having computers carried out the image processing method of the second aspect, that is, having those carried out the inputting step, the reading step, the calculating step, and the determining step. By having the computers carried out this program, the above described useful effects can be successfully achieved.
These and other objects, features, aspects and advantages of the present invention will become more apparent from the following detailed description of the present invention when taken in conjunction with the accompanying drawings.